﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.Utility;
using AjaxPro;
using System.Data.SqlClient;

namespace EnvironmentManagerSystem.EvaluationUnitManager
{
    public partial class EUMselect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                DropDownListBind(string.Empty);
                BindGridView();
                id.Text = Session["evaluationunitID"].ToString();
            }
        }

        #region 绑定类别DropDownList(环评类别、环统类别、项目负责人)(x)
        public void DropDownListBind(string Deparatment)
        {
            //环评类别
            ddlhuanpingleibie.DataSource = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("7");
            ddlhuanpingleibie.DataBind();
            ddlhuanpingleibie.Items.Insert(0, new ListItem("请选择", "请选择"));
            ddlhuanpingleibie.Items.Insert(1, new ListItem("全部", "全部"));
            //环统类别
            ddlESIndustryType.DataSource = EnvironmentManagerSystem.BLL.ConstructionUnit.Gethylb("75");
            ddlESIndustryType.DataBind();
            ddlESIndustryType.Items.Insert(0, new ListItem("请选择", "请选择"));
            ddlESIndustryType.Items.Insert(1, new ListItem("全部", "全部"));
            //项目负责人(环评部门项目负责人)
            ddlxiangmufuzheren.DataSource = EnvironmentManagerSystem.BLL.XIANGMU.GetFuzeren(Deparatment);
            ddlxiangmufuzheren.DataTextField = "UserName";
            ddlxiangmufuzheren.DataValueField = "ID";
            ddlxiangmufuzheren.DataBind();
            ddlxiangmufuzheren.Items.Insert(0, new ListItem("请选择", "请选择"));
            ddlxiangmufuzheren.Items.Insert(1, new ListItem("全部", "全部"));
        }
        #endregion

        #region GridView(绑定、排序)(x)
        private void BindGridView()
        {
            // 获取GridView排序数据列及排序方向   
            string sortExpression = this.GridView1.Attributes["SortExpression"];
            string sortDirection = this.GridView1.Attributes["SortDirection"];
            // 调用业务数据获取方法   
            DataTable dtBind = this.getDB();
            // 根据GridView排序数据列及排序方向设置显示的默认数据视图   
            if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
            {
                dtBind.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
            }
            // GridView绑定并显示数据   
            this.GridView1.DataSource = dtBind;
            this.GridView1.DataBind();
        }
        // DataTable 数据源     
        private DataTable getDB()
        {
            DataTable dt = NoticeService.GetSelectAllP(Session["evaluationunitID"].ToString());
            return dt;
        }
        public SortDirection GridViewSortDirection
        {
            get
            {
                if (ViewState["sortDirection"] == null)
                    ViewState["sortDirection"] = SortDirection.Ascending;
                return (SortDirection)ViewState["sortDirection"];
            }
            set { ViewState["sortDirection"] = value; }
        }
        private void SortGridView(string sortExpression, string direction)
        {
            DataTable dt = getDB();
            DataView dv = new DataView(dt);
            dv.Sort = sortExpression + direction;
            GridView1.DataSource = dv; //将DataView绑定到GridView上
            GridView1.DataBind();
        }
        //处理GridView的排序事件
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (GridViewSortDirection == SortDirection.Ascending) //设置排序方向
            {
                GridViewSortDirection = SortDirection.Descending;
                SortGridView(sortExpression, " DESC");
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                SortGridView(sortExpression, " ASC");
            }
        }
        #endregion

        #region 按钮(查询、重置)
        protected void lbtnSelect_Click(object sender, EventArgs e)
        {
            lbtnBind();
        }
        private void lbtnBind()
        {
            if (txtXiangMuShouLiShiJianK.Text == "" && txtXiangMuShouLiShiJianJ.Text != "")
            {
                Response.Write("<script language='javascript'>alert('请填写要查询的受理起始时间！');</script>");
            }
            if (txtXiangMuShouLiShiJianK.Text != "" && txtXiangMuShouLiShiJianJ.Text == "")
            {
                Response.Write("<script language='javascript'>alert('请填写要查询的受理结束时间！');</script>");
            }
            //项目名称,受理日期开始时间,结束时间,项目负责人,环统类别,环评类别,报告书,报告表,受理退回, 建设性质(新建), 建设性质(改扩建),建设性质(技术改造) 
            GridView1.DataSource = NoticeService.GetSelectp(id.Text, txtProjectName.Text, txtXiangMuShouLiShiJianK.Text, txtXiangMuShouLiShiJianJ.Text, ddlxiangmufuzheren.SelectedItem.Text, ddlESIndustryType.SelectedValue, ddlhuanpingleibie.SelectedValue, cbReports.Checked, cbReportb.Checked, cbshoulituihuishanchu.Checked, rbR1.Checked, rbR2.Checked, rbR3.Checked);
            GridView1.DataBind();
        }
        protected void lbtReset_Click(object sender, EventArgs e)
        {
            txtProjectName.Text = null;//项目名称
            txtXiangMuShouLiShiJianK.Text = null;//受理开始日期
            txtXiangMuShouLiShiJianJ.Text = null;//受理结束日期
            ddlxiangmufuzheren.SelectedValue = null;//项目负责人
            ddlESIndustryType.SelectedValue = null;//环统类别
            ddlhuanpingleibie.SelectedValue = null;//环评类别
            cbReports.Checked = false;//报告书
            cbReportb.Checked = false;//报告表
            cbshoulituihuishanchu.Checked = false;//受理退回
            rbR1.Checked = false;//建设性质(新建)
            rbR2.Checked = false;//建设性质(改扩建)
            rbR3.Checked = false;//建设性质(技术改造)
        }
        #endregion

        //鼠标滑动
        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            OfficeHelper.HelpDv(GridView1);
        }
    }
}
